﻿using Bear.Library.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Bear.Models
{
    public class 配置文件
    {
        private AppConfig _Config;
        public 配置文件(AppConfig config)
        {
            _Config = config;
        }

        public string 游戏路径
        {
            get
            {
                return _Config.GamePath;
            }
            set
            {
                _Config.GamePath = value;
            }
        }

        public int 频道
        {
            get
            {
                return _Config.Channel;
            }
            set
            {
                _Config.Channel = value;
            }
        }

     
       
    }


    [Serializable]
    public class AppConfig
    {
        public const string CONFIG_PATH = "config.xml";
        
        //验证时间
        public int AlarmInterval { get; set; }

        //验证窗口时离线
        public bool IsVerificationOffline { get; set; }

        //报警频率
        public int AlarmPitch { get; set; }


        //台阶等待时间
        public int StepWaitTime { get; set; }

        //按键比率,默认90
        public int KeyRate { get; set; }
        //移动距离,默认5
        public int MoveDistance { get; set; }
        //拾取时间，默认50
        public int PickCycleTime { get; set; }
        /// <summary>
        /// 生命百分比
        /// </summary>
        public int LifeRate { get; set; }
        /// <summary>
        /// 魔力百分比
        /// </summary>
        public int MagicRate { get; set; }

        /// <summary>
        /// 生命药水剂量
        /// </summary>
        public int LifePotion { get; set; }
        /// <summary>
        /// 魔力药水剂量
        /// </summary>
        public int MagicPotion { get; set; }

        /// <summary>
        /// 生命循环时间
        /// </summary>
        public int LifeCycleTime { get; set; }
        /// <summary>
        /// 魔力循环时间
        /// </summary>
        public int MagicCycleTime { get; set; }

        public static AppConfig GetDefault()
        {
            return new AppConfig()
            {
                GamePath = @"E:\Maple\GameLauncher.exe",
                GameTitle = "MapleStory",
                Channel = 10,
                AlarmInterval = 20000,
                IsVerificationOffline = false,
                AlarmPitch = 440,
                StepWaitTime = 1500,
                KeyRate = 90,
                MoveDistance = 5,
                PickCycleTime = 50,
                LifeRate = 80,
                MagicRate = 50,
                LifePotion = 5,
                MagicPotion = 1,
                LifeCycleTime = 1500,
                MagicCycleTime = 2000,
            };
        }


        public string GamePath { get; set; }

        public string GameTitle { get; set; }

        public bool IsDebug { get; set; }

        public static AppConfig Load()
        {
            if (!File.Exists(AppConfig.CONFIG_PATH))
            {
                return AppConfig.GetDefault();
            }

            return SerializerHelper.XmlDeserialize<AppConfig>(AppConfig.CONFIG_PATH);
        }

        public void Save()
        {
            SerializerHelper.XmlSerializer(this, AppConfig.CONFIG_PATH);
        }


        public int Channel { get; set; }

    }



}
